package com.yunao.service.impl;

import com.yunao.dao.FunctionRepository;
import com.yunao.entity.Function;
import com.yunao.service.FunctionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class FunctionServiceImpl implements FunctionService {

    @Autowired
    private FunctionRepository functionRepository;

    @Override
    public void InsertOne(Function function) {
        functionRepository.save(function);
    }

    @Override
    public Function findByOrganId(Integer organid) {
        Function byOrganIdAndType = functionRepository.findAllByOrganIdAndType(organid, 2);//组织
        return byOrganIdAndType;
    }

    @Override
    public Function findByUserId(Integer userid) {
        Function byUserId = functionRepository.findAllByUserId(userid);
        return byUserId;
    }

    @Override
    public Function findById(Integer id) {
        Optional<Function> byId = functionRepository.findById(id);
        return byId.get();
    }

    @Override
    public void updateOne(Function function) {
        functionRepository.saveAndFlush(function);
    }
}
